import ldap
l = ldap.initialize("ldap://localhost:389", 1)
d = l.get_option(ldap.OPT_DEBUG_LEVEL)
print d
l.set_option(ldap.OPT_DEBUG_LEVEL,255)
d = l.get_option(ldap.OPT_DEBUG_LEVEL)
print d
l.bind_s("cn=admin,dc=erikin,dc=com","mypassword")

## inetOrgPerson (openldap)
# dn = "cn=a,cn=abcgroup,ou=abc,ou=support_erikin_com,ou=web,ou=centweb,ou=applications,dc=erikin,dc=com"
# objectAttributes =  [('cn', 'a'), ('givenName', 'asdf'), ('objectClass', 'inetOrgPerson'),  ('sn', 'a'), ('uid', 'a'), ('userPassword', '{md5}CY9rzUYh03PK3k6DJie09g==')]

## organizationalUnit (openldap)
# dn = "ou=speeves,ou=support_erikin_com,ou=web,ou=centweb,ou=applications,dc=erikin,dc=com"
# objectAttributes =  [('ou', 'speeves'), ('objectClass', 'organizationalUnit')]

l.add_s(dn, objectAttributes)

x = l.search_s("ou=support_erikin_com,ou=web,ou=centweb,ou=applications,dc=erikin,dc=com", ldap.SCOPE_SUBTREE, "objectClass=organizationalUnit")
print x

